import mxgraph from 'src/pages/mxgraph/graph/index';
import { Graph } from 'src/pages/mxgraph/graph/Graph';

const {
  mxCylinder,
  mxUtils,
  mxRectangle,
  mxCellRenderer,
  mxActor,
  mxConstants,
  mxPoint,
  mxPerimeter,
  mxStyleRegistry,
  mxConnectionConstraint,
  mxShape,
  mxRhombus,
  mxRectangleShape,
  mxHexagon,
  mxEllipse,
  mxDoubleEllipse,
  mxArrowConnector,
  mxConnector,
  mxMarker,
  mxEdgeStyle,
  mxLabel,
  mxImageShape,
  mxSwimlane,
  mxLine,
  mxTriangle,
  mxCloud,
  mxArrow,
  mxElbowEdgeHandler,
} = mxgraph;

/**
 * Copyright (c) 2006-2015, JGraph Ltd
 */

/**
 * Registers shapes.
 */
(function () {
 
  //// UML Frame Shape
  function UmlSequenceFrame() {
    mxShape.call(this);
  };
  mxUtils.extend(UmlSequenceFrame, mxShape);
  UmlSequenceFrame.prototype.width = 60;
  UmlSequenceFrame.prototype.height = 30;
  UmlSequenceFrame.prototype.corner = 5;
  UmlSequenceFrame.prototype.getLabelMargins = function (rect) {
    return new mxRectangle(0, 0,
      rect.width - (parseFloat(mxUtils.getValue(this.style, 'width', this.width) * this.scale)),
      rect.height - (parseFloat(mxUtils.getValue(this.style, 'height', this.height) * this.scale)));
  };
  UmlSequenceFrame.prototype.paintBackground = function (c, x, y, w, h) {
    let co = this.corner;
    let w0 = Math.min(w, Math.max(co, parseFloat(mxUtils.getValue(this.style, 'width', this.width))));
    let h0 = Math.min(h, Math.max(co * 1.5, parseFloat(mxUtils.getValue(this.style, 'height', this.height))));
    let bg = mxUtils.getValue(this.style, mxConstants.STYLE_SWIMLANE_FILLCOLOR, mxConstants.NONE);

    if (bg != mxConstants.NONE) {
      c.setFillColor(bg);
      c.rect(x, y, w, h);
      c.fill();
    }

    if (this.fill != null && this.fill != mxConstants.NONE && this.gradient && this.gradient != mxConstants.NONE) {
      let b = this.getGradientBounds(c, x, y, w, h);
      c.setGradient(this.fill, this.gradient, x, y, w, h, this.gradientDirection);
    } else {
      c.setFillColor(this.fill);
    }

    c.begin(); 
    c.moveTo(x, y);
    c.lineTo(x + w0, y);
    c.lineTo(x + w0, y + Math.max(0, h0 - co * 1.5));
    c.lineTo(x + Math.max(0, w0 - co), y + h0);
    c.lineTo(x, y + h0);
    c.close();
    c.fillAndStroke();

    c.begin();
    c.moveTo(x + w0, y);
    c.lineTo(x + w, y);
    c.lineTo(x + w, y + h);
    c.lineTo(x, y + h);
    c.lineTo(x, y + h0);
    c.stroke();
  };

  mxCellRenderer.registerShape('umlSequenceFrame', UmlSequenceFrame);
  
})();
